{template 'common/header'}
{template 'common_css'}

<ul class="nav nav-tabs">
	<li {if $operation == 'post' && empty($id)}class="active"{/if}><a href="{php echo $this->createWebUrl('category', array('op' => 'post'))}">添加主题</a></li>
	<li {if $operation == 'display'}class="active"{/if}><a href="{php echo $this->createWebUrl('category', array('op' => 'display'))}">管理主题</a></li>
    {if $operation == 'post' && !empty($id)}<li class="active"><a href="#">
    编辑主题
    </a></li>{/if}
</ul>

{if $operation == 'post'}

<div class="main">

    <form action="" method="post" class="form-horizontal form" enctype="multipart/form-data" id="form1">
        <div class="panel panel-default">
            <div class="panel-heading">分类详细设置</div>
            <div class="panel-body">
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">主题名称</label>
                    <div class="col-sm-9">
                        <input type="text" name="title" class="form-control" value="{$cate['title']}" />
                    </div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">启用状态</label>
					<div class="col-xs-12 col-sm-9">
					<div class="btn-group" data-toggle="buttons">					  
						<label class="btn btn-default {if empty($cate) || $cate['status'] == 1}active{/if}"><input type="radio" name="status" value="1" {if empty($cate) || $cate['status'] == 1}checked="checked"{/if} >启用</label>
						<label class="btn btn-default {if !empty($cate) && $cate['status'] == 0}active{/if}"><input type="radio" name="status" value="0" {if !empty($cate) && $cate['status'] == 0} checked="checked"{/if}>关闭</label>
					</div>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">允许粉丝匿名</label>
					<div class="col-xs-12 col-sm-9">
					<div class="btn-group" data-toggle="buttons">					  
						<label class="btn btn-default {if $cate['hide'] == 1}active{/if}"><input type="radio" name="hide" value="1" {if $cate['hide'] == 1}checked="checked"{/if} >启用</label>
						<label class="btn btn-default {if empty($cate) || $cate['hide'] == 0}active{/if}"><input type="radio" name="hide" value="0" {if empty($cate) || $cate['hide'] == 0} checked="checked"{/if}>关闭</label>
					</div>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">允许发图</label>
					<div class="col-xs-12 col-sm-9">
					<div class="btn-group" data-toggle="buttons">					  
						<label class="btn btn-default {if $cate['pic'] == 1}active{/if}"><input type="radio" name="pic" value="1" {if $cate['pic'] == 1}checked="checked"{/if} >启用</label>
						<label class="btn btn-default {if empty($cate) || $cate['pic'] == 0}active{/if}"><input type="radio" name="pic" value="0" {if empty($cate) || $cate['pic'] == 0} checked="checked"{/if}>关闭</label>
					</div>
					</div>
				</div>
                
			</div>
		</div>
		<div class="form-group col-sm-12">
			<input type="submit" name="submit" value="提交" class="btn btn-primary col-lg-1" />
			<input type="hidden" name="token" value="{$_W['token']}" />
		</div>
    </form>
</div>
<script type="text/javascript" src="../web/resource/components/colorpicker/spectrum.js"></script>
<link type="text/css" rel="stylesheet" href="../web/resource/components/colorpicker/spectrum.css" />
<script type="text/javascript">
<!--
	$(function(){
		colorpicker();
	});
//-->
</script>
{elseif $operation == 'display'}

<div class="main">
    <div class="store">
        <form action="" method="post" onsubmit="return formcheck(this)">
			<div class="panel panel-default">
				<div class="panel-body table-responsive">
					<table class="table table-hover">
						<thead>
							<tr>
								<th style="width:50px;">ID</th>
								<th>主题名称</th>
								<th>管理</th>
								<th style="width:8%;">状态</th>
								<th style="width:8%;">匿名</th>
								<th style="width:8%;">多图</th>
								<th style="width:180px;">操作</th>
							</tr>
						</thead>
						<tbody>
			{loop $category $row}
				<tr>
					<td>{$row['id']}</td>
					<td><div class="type-parent">{$row['title']}</div></td>
					<td>
						<a href="{php echo $this->createWebUrl('comment', array('op' => 'display', 'cid' => $row['id']))}" class="btn btn-info"><i class="fa fa-comments-o"></i> 评论管理 <span class="badge">{$row['a']}</span></a>
						<a href="{php echo $this->createWebUrl('comment', array('op' => 'display', 'cid' => $row['id'], 'recycle'=>'1'))}" class="btn btn-default"><i class="fa fa-trash-o"></i> 回收站 <span class="badge">{$row['d']}</span></a>
					</td>
					<td>
						<a data="{$row['status']}" href="javascript:;" class="label label-default {if $row['status']==1}label-primary{/if}" onclick="set(this,{$row['id']},'status','dayu_comment_category')">{if $row['status']==1}<i class="fa fa-check-square-o"></i> 已开启{else}<i class="fa fa-times-circle-o"></i> 已关闭{/if}</a>
					</td>
					<td>
						<a data="{$row['hide']}" href="javascript:;" class="label label-default {if $row['hide']==1}label-primary{/if}" onclick="set(this,{$row['id']},'hide','dayu_comment_category')">{if $row['hide']==1}<i class="fa fa-check-square-o"></i> 已开启{else}<i class="fa fa-times-circle-o"></i> 已关闭{/if}</a>
					</td>
					<td>
						<a data="{$row['pic']}" href="javascript:;" class="label label-default {if $row['pic']==1}label-primary{/if}" onclick="set(this,{$row['id']},'pic','dayu_comment_category')">{if $row['pic']==1}<i class="fa fa-check-square-o"></i> 已开启{else}<i class="fa fa-times-circle-o"></i> 已关闭{/if}</a>
					</td>
					<td>
						<a href="{php echo $this->createWebUrl('category', array('op' => 'post', 'id' => $row['id']))}" class="btn btn-default"><i class="fa fa-edit"></i> 编辑</a>
						{if empty($row['a'])}<a href="{php echo $this->createWebUrl('category', array('op' => 'delete', 'id' => $row['id']))}" class="btn btn-danger" onclick="return confirm('确认删除此分类吗？');return false;"><i class="fa fa-remove"></i> 删除</a>{/if}
					</td>
				</tr>
			{/loop}
			</tbody>
					</table>
				</div>
           </div>
		<div class="form-group col-sm-12">
			<a href="{php echo $this->createWebUrl('category', array('op' => 'post'))}" class="btn btn-default btn-primary"><i class="fa fa-plus-circle"></i> 添加新分类</a>
		</div>
        </form>
{$pager}
    </div>
</div>
	<script>
	function set(obj,id,type,table){
		$(obj).html($(obj).html() + "...");
		$.post("{php echo $this->createWebUrl('ajaxset')}",{id:id,type:type,table:table, data: obj.getAttribute("data")},function(d){
			$(obj).html($(obj).html().replace("...",""));
				$(obj).html( d.data=='1'?'<i class="fa fa-check-square-o"></i> 已开启':'<i class="fa fa-times-circle-o"></i> 已关闭');

			$(obj).attr("data",d.data);
			if(d.result==1){
				$(obj).toggleClass("label-primary");
	//			$("#c_"+id).hide();
			}
		},"json");
	}
	</script>
{/if}
{template 'common/footer'}